﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace ITSupportPlatformWindowsService
{
    public partial class SyncService : ServiceBase
    {
        public System.Timers.Timer looper;
        public bool isOk = true;

        public SyncService()
        {
            InitializeComponent();
            InitConfig();
            looper = new System.Timers.Timer(1000);//5*60*
            looper.Elapsed += new System.Timers.ElapsedEventHandler(looper_Elapsed);
        }

        private void InitConfig()
        {
            string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config");
            //log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(path));
        }

        void looper_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                SyncDataService syncInfo = new SyncDataService();
                //SyncDataService.ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
                syncInfo.DoSyncData();
            }
            catch (Exception ex)
            {

            }
            finally
            {

            }
        }

        protected override void OnStart(string[] args)
        {
            looper.Start();
        }

        protected override void OnStop()
        {
            looper.Stop();
        }
    }
}
